home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / amiga / animutil / kfast / kfast.lzh / KFAST / src / objects.c < prev    next >
C/C++ Source or Header  |  1992-07-03  |  5KB  |  231 lines

  1. #include "skeleton.h"
  2.  
  3. /* object, object chain, and frame manipulation primitives */
  4.  
  5. obj_ptr locateframe(obj_ptr object)
  6.     {
  7.     if(object==NULL) return(NULL);
  8.     while(object->frameup!=NULL)
  9.         object = object->frameup;
  10.     return(object);
  11.     }
  12.  
  13. obj_ptr locatestart(obj_ptr object)
  14.     {
  15.     if(object==NULL) return(NULL);
  16.     while(object->prev!=NULL)
  17.         object = object->prev;
  18.     return(object);
  19.     }
  20.  
  21. void moveobject(obj_ptr object,int dx,int dy)
  22.     {
  23.     if(object!=NULL)
  24.         {
  25.         object->offset[0] = object->offset[0] + dx;
  26.         object->offset[1] = object->offset[1] + dy;
  27.         }
  28.     }
  29.  
  30. void moveobjectchain(obj_ptr object,int dx,int dy)
  31.     {
  32.     while(object!=NULL)
  33.         {
  34.         object->offset[0] = object->offset[0] + dx;
  35.         object->offset[1] = object->offset[1] + dy;
  36.         object = object->next;
  37.         }
  38.     }
  39.  
  40. void addimage(obj_ptr object,line_ptr line,int type)
  41. {
  42.     if(line!=NULL)
  43.     {
  44.         if(type==IMAGE)
  45.             object->image = line;
  46.         else if(type==SKELETON)
  47.             object->skeleton = line;
  48.         else if(type==XOUTLINE)
  49.             object->outline = line;
  50.         object->entry = object->entry & type;
  51.     }
  52. }
  53.  
  54. obj_ptr makeobject(void)
  55.     {
  56.     obj_ptr object;
  57.  
  58.     object = (obj_ptr)malloc(sizeof(struct object));
  59.  
  60.     object->offset[0] = 0;
  61.     object->offset[1] = 0;
  62.     object->next = NULL;
  63.     object->prev = NULL;
  64.     object->frameup = NULL;
  65.     object->framedown = NULL;
  66.     object->image = NULL;
  67.     object->skeleton = NULL;
  68.     object->outline = NULL;
  69.     object->entry = 0;
  70.     object->ilaw = 0;
  71.  
  72.     return(object);
  73.     }
  74.  
  75. void mergeobject(obj_ptr object,obj_ptr append)
  76.     {
  77.     int fixx,fixy,i;
  78.     line_ptr line;
  79.  
  80.     fixx = 0;
  81.     fixy = 0;
  82.  
  83.     if(object==NULL || append==NULL) return;
  84.  
  85.     fixx = object->offset[0] - append->offset[0];
  86.     fixy = object->offset[1] - append->offset[1];
  87.  
  88.     if(append->image!=NULL)
  89.         {
  90.         if(fixx!=0 || fixy!=0)
  91.             {
  92.             line = append->image;
  93.             while(line!=NULL)
  94.                 {
  95.                 for(i=0;i<line->number;i++)
  96.                     {
  97.                     line->pts->p[i][0] = line->pts->p[i][0] + fixx;
  98.                     line->pts->p[i][1] = line->pts->p[i][1] + fixy;
  99.  
  100.                     }
  101.                 line = line->next;
  102.                 }
  103.              }
  104.         if(object->image!=NULL)
  105.             appendline(object->image,append->image);
  106.         else
  107.             object->image = append->image;
  108.         }
  109.     if(object->skeleton==NULL)
  110.         {
  111.         if(fixx!=0 || fixy!=0)
  112.             {
  113.             line = append->skeleton;
  114.             while(line!=NULL)
  115.                 {
  116.                 for(i=0;i<line->number;i++)
  117.                     {
  118.                     line->pts->p[i][0] = line->pts->p[i][0] + fixx;
  119.                     line->pts->p[i][1] = line->pts->p[i][1] + fixy;
  120.                     }
  121.                 line = line->next;
  122.                 }
  123.              }
  124.         object->skeleton = append->skeleton;
  125.         }
  126.     if(object->outline==NULL)
  127.         {
  128.         if(fixx!=0 || fixy!=0)
  129.             {
  130.             line = append->outline;
  131.             while(line!=NULL)
  132.                 {
  133.                 for(i=0;i<line->number;i++)
  134.                     {
  135.                     line->pts->p[i][0] = line->pts->p[i][0] + fixx;
  136.                     line->pts->p[i][1] = line->pts->p[i][1] + fixy;
  137.                     }
  138.                 line = line->next;
  139.                 }
  140.              }
  141.         object->outline = append->outline;
  142.         }
  143.     }
  144.  
  145. void addobject(obj_ptr chain,obj_ptr object,int frames)
  146. /* frames is the number of frames after chain that object is added */
  147. {
  148.     if(chain == NULL) return;
  149.     for(;frames>1;frames--)
  150.     {
  151.         if(chain->next==NULL)
  152.     {
  153.             chain->next = makeobject();
  154.         chain->next->prev = chain;
  155.     }
  156.     chain=chain->next;
  157.     }
  158.     if(chain->next==NULL)
  159.     {
  160.         chain->next = object;
  161.     object->prev = chain;
  162.     }
  163.     else
  164.         mergeobject(chain->next,object);
  165. }
  166.  
  167. void addchain(obj_ptr frame,obj_ptr chain)
  168. {
  169.     obj_ptr find;
  170.  
  171.     if(frame == NULL) return;
  172.  
  173.     while(chain!=NULL)
  174.     {
  175.         find = frame;
  176.         while(find->framedown!=NULL)
  177.             find = find->framedown;
  178.  
  179.         chain->frameup = find;
  180.         find->framedown = chain;
  181.         chain = chain->next;
  182.         if(chain!=NULL)
  183.         {
  184.             if(frame->next==NULL)
  185.         {
  186.                 frame->next = makeobject();
  187.         frame->next->prev = frame;
  188.         }
  189.             frame = frame->next;
  190.         }
  191.     }
  192. }
  193.  
  194. void removechain(obj_ptr chain)
  195. {
  196.     while(chain!=NULL)
  197.     {
  198.         chain->frameup->framedown = chain->framedown;
  199.         chain->framedown->frameup = chain->frameup;
  200.         chain->frameup = NULL;
  201.         chain->framedown = NULL;
  202.     chain = chain->next;
  203.     }
  204. }
  205.  
  206. void deletechain(obj_ptr chain)
  207. {
  208.     obj_ptr next;
  209.  
  210.     if(chain==NULL) return;
  211.     while(chain!=NULL)
  212.     {
  213.         next = chain->next;
  214.         if(chain->image!=NULL) deleteline(chain->image);
  215.         if(chain->skeleton!=NULL) deleteline(chain->skeleton);
  216.         if(chain->outline!=NULL) deleteline(chain->outline);
  217.         free(chain,sizeof(struct object));
  218.         chain = next;
  219.     }
  220. }
  221.  
  222. /*
  223. copyobject(object)
  224.  
  225. copychain(chain)
  226.  
  227. insertframe(frame)
  228.  
  229. deleteframe(frame)
  230.  */
  231.